/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	LevelOfDetail.cpp
*
*	Comments	-	See LevelOfDetail.h
*
**************************************************************************************/
#include "../Include/LevelOfDetail.h"
#include "../Include/String.h"

namespace Pulse
{
	EErrorCode::Type LevelOfDetail::Add( INDEX_T viewIndex, INDEX_T LODIndex, Geometry *pGeometry )
	{
		INT foundViewIndex = -1; 

		// Search if view type already exists
		SIZE_T size = m_viewLODList.GetSize();
		ViewLODMap *pViewLODMap;
		for ( SIZE_T i = 0; i < size; ++i )
		{
			pViewLODMap = &m_viewLODList[i];

			// If viewIndex exists, search the LOD index if it exists
			if ( pViewLODMap->viewIndex == viewIndex )
			{
				foundViewIndex = (INT)viewIndex;

				LODMapList *pLODMapList = &pViewLODMap->LODList;
				SIZE_T LODSize = pLODMapList->GetSize();
				for ( SIZE_T j = 0; j < LODSize; ++j )
				{
					//// If we found the View/LOD index combination ignore this
					//if ( (*pLODMapList)[j].LODIndex == LODIndex )
					//{
					//	PSX_PushWarning( "View and LOD index already exists. Skipping this LOD entry." );
					//	return EErrorCode::LOGIC;
					//}
				}

				// View found but no LOD found.
				break;
			}
		}

		// If we get here LOD entry doesn't exist. Proceed with add
		// Take advantage of avoiding another loop if view index already exists
		if ( foundViewIndex != -1 )
		{
			// pViewLODMap should already be pointing to the right view.
			// Particular rule is that LOD should be in ascending order
			LODMapList *pLODMapList = &pViewLODMap->LODList;
			SIZE_T LODSize = pLODMapList->GetSize();
			if ( LODSize )
			{
				(*pLODMapList)[LODSize-1];
			}
			else
			{

			}
		}

		return EErrorCode::OKAY;
	}
}